/**
 * @Author: xzm
 * @Date: 2019/9/10
 */
import axios from '@/api/fetch';
import SERVER from '@/api/server';
//  加载品牌接口
//export const getBrand = params => { return { "data": [{ "brandId": 1, "brandCode": "GMMC", "brandName": "广汽三菱" }, { "brandId": 2, "brandCode": "MMSCN", "brandName": "进口三菱" }] } };
export const getBrand = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsqueryall`,{params:_params});
//  加载车系接口
//export const getSeries = params => { return { "data": [{ "seriesId": 1, "brandId": 1, "appId": "cyx", "seriesCode": "CK", "seriesName": "帕杰罗", "dataSources": "10451001", "brandName": "广汽三菱" }, { "seriesId": 2, "brandId": 1, "appId": "cyx", "seriesCode": "ZC", "seriesName": "劲炫", "brandName": "广汽三菱" }] } }
export const getSeries = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${_params.brandId}/seriessdict`,{params:_params});
//  加载车型接口
//export const getModel = params => { return { "data": [{ "brandId": 1, "brandCode": "GMMC", "brandName": "广汽三菱", "seriesId": 1, "seriesCode": "CK", "seriesName": "帕杰罗", "modelCode": "CK_2005", "modelName": "CK_2005", "modelGroupName": null, "modelId": 1 }, { "brandId": 1, "brandCode": "GMMC", "brandName": "广汽三菱", "seriesId": 2, "seriesCode": "ZC", "seriesName": "劲炫", "modelCode": "ZC2012G4", "modelName": "ZC2012 国4", "modelGroupName": null, "modelId": 2 }, { "brandId": 1, "brandCode": "GMMC", "brandName": "广汽三菱", "seriesId": 2, "seriesCode": "ZC", "seriesName": "劲炫", "modelCode": "ZC2013G5", "modelName": "ZC2013 国5", "modelGroupName": null, "modelId": 3 }, { "brandId": 1, "brandCode": "GMMC", "brandName": "广汽三菱", "seriesId": 3, "seriesCode": "CR45", "seriesName": "劲畅", "modelCode": "CR452013", "modelName": "劲畅2013款", "modelGroupName": null, "modelId": 4 }] } };
export const getModel = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${_params.brandId}/seriessdict/${_params.seriesId}/modelsdict`,{params:_params});
//  加载配置数据
//export const getPackage = params => { return { "data": [{ "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "帕杰罗", "seriesId": 1, "modelId": 1, "modelCode": "CK_2005", "modelName": "CK_2005", "configCode": "CFA2031GD", "configName": "CFA2031GD(标准灰内)", "packageId": 1 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "帕杰罗", "seriesId": 1, "modelId": 1, "modelCode": "CK_2005", "modelName": "CK_2005", "configCode": "CFA2031GP", "configName": "CFA2031GP(标准灰内)", "packageId": 2 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "帕杰罗", "seriesId": 1, "modelId": 1, "modelCode": "CK_2005", "modelName": "CK_2005", "configCode": "CFA2031G", "configName": "CFA2031G(豪华灰内)", "packageId": 3 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "帕杰罗", "seriesId": 1, "modelId": 1, "modelCode": "CK_2005", "modelName": "CK_2005", "configCode": "CFA2031HP", "configName": "CFA2031HP(标准灰内)", "packageId": 4 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "帕杰罗", "seriesId": 1, "modelId": 1, "modelCode": "CK_2005", "modelName": "CK_2005", "configCode": "CFA2031H", "configName": "CFA2031H(豪华灰内)", "packageId": 5 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "劲炫", "seriesId": 2, "modelId": 2, "modelCode": "ZC2012G4", "modelName": "ZC2012 国4", "configCode": "GMC6430A", "configName": "GMC6430A(标准灰内)", "packageId": 6 }, { "taxPurchasePrice": null, "brandId": 1, "brandName": "广汽三菱", "seriesName": "劲炫", "seriesId": 2, "modelId": 2, "modelCode": "ZC2012G4", "modelName": "ZC2012 国4", "configCode": "GMC6431A", "configName": "GMC6431A(舒适灰内)", "packageId": 7 }] } };
export const getPackage = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/brandsdict/${_params.brandId}/seriessdict/${_params.seriesId}/modelsdict/${_params.modelId}/packagesdict`,{params:_params});
//  加载颜色
//export const getColor = params => { return { "data": [{ "colorId": 1, "dealerCode": null, "appId": "cyx", "colorType": 16081002, "colorCode": "9100", "colorName": "新酷银_灰", "dataSources": 10451001, "isValid": 10041001 }, { "colorId": 2, "dealerCode": null, "appId": "cyx", "colorType": 16081002, "colorCode": "9101", "colorName": "新极地白_米", "dataSources": 10451001, "isValid": 10041001 }] } };
export const getColor = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/color/getColorByPackageId?packageId=${_params.packageId}`,{params:_params});
//  加载产品数据-分页查询
export const getProduct = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/productInfo`,  {params:_params});
//  加载车型数据-分页查询
export const getModelPage = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/models`,  {params:_params});
//  加载车型数据-不分页查询
export const getModelAll = _params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/models/all`,  {params:_params});
//  车系车型树形结构
export const getSeriesModelTree = () => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/vehicleProduct/seriesModelTree`);


/**
 * 根据销售公司加载车系数据-查询
 * @param {*} params 按多个销售公司查询参数:financeCompanyIds = "1,2,3"
 */
export const findFinanceCompanySeriesList = params => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/financeCompanySeries/getList`,  {params,menuId:'-1'});

export const getSeriesByPowerType = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/series/querySeriesByCondition`,{params:params});

export const getDealerAttachAuth = params => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/financeCompanySeries/getDealerAttachAuth`,  {params,menuId:'-1'});

/**
 * 将数据转换成下拉列表数据格式
 * @param {*} sourceDataList
 * @param {*} val
 * @param {*} txt
 */
export const toSelectData = (sourceDataList, val, txt) => {
  let resultArray = new Array();
  if (sourceDataList != null && sourceDataList.length > 0) {
    sourceDataList.forEach(element => {
      let selectObj = new Object();
      selectObj.text = element[txt];
      selectObj.value = element[val];
      resultArray.push(selectObj);
    });
  }
  return resultArray;
}
